using Gateway.Common.Entity;
using Gateway.Common.Enums;

namespace Gateway.Domain.Entities;

/// <summary>
/// 部门表
/// </summary>
[PrimaryIdAttribute("DEP")]
public class Department : AggregateRootEntityBase
{
    public Department(string departName = default, string parentId = default, string remark = default, int seqNo = 0,
        string parentLevelCode = default)
    {
        DepartName = departName;
        ParentId = parentId;
        Remark = remark;
        SeqNo = seqNo;
        DepartmentCode = "DPT" + DateTime.Now.ToString("yyyyMMddHHmmss") + (new Random().Next(0, 1000));
        LevelCode = parentLevelCode + DepartmentCode;
    }

    /// <summary>
    /// 更新
    /// </summary>
    /// <param name="departName"></param>
    /// <param name="parentId"></param>
    /// <param name="remark"></param>
    /// <param name="seqNo"></param>
    /// <param name="parentLevelCode">父级层级编码</param>
    public void Update(string departName = default, string parentId = default, string remark = default, int seqNo = 0,
        string parentLevelCode = default)
    {
        DepartName = departName;
        ParentId = parentId;
        Remark = remark;
        SeqNo = seqNo;
        if (!string.IsNullOrWhiteSpace(parentLevelCode))
        {
            LevelCode = parentLevelCode + DepartmentCode;
        }
    }

    /// <summary>
    /// 部门编码
    /// </summary>
    public string DepartmentCode { get; private set; }

    /// <summary>
    /// 层级编码
    /// </summary>
    public string LevelCode { get; private set; }

    /// <summary>
    /// 部门名称
    /// </summary>
    public string DepartName { get; private set; }

    /// <summary>
    /// 父级标识
    /// </summary>
    public string ParentId { get; private set; }

    /// <summary>
    /// 备注
    /// </summary>
    public string Remark { get; private set; }

    /// <summary>
    /// 序号
    /// </summary>
    public int SeqNo { get; private set; }

    public Department()
    {
    }
}